﻿--|--------------------------------------------------------------------------------
--| [InsertCar] - Insert Procedure Script for Game
--|--------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id (N'[dbo].[InsertCar]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1) 
  DROP PROCEDURE [dbo].[InsertCar]
GO

CREATE PROCEDURE [dbo].[InsertCar]
(
	@ID int output, 
	@Name nvarchar(50), 
	@Description nvarchar(50), 
	@MaxSendingPause int,
	@Model nvarchar(250),
	@RegistrationNumber nvarchar(50),
	@Color nvarchar(50))
AS
	SET NOCOUNT ON

DECLARE @TeamID int
SELECT TOP 1  @TeamID = ID FROM Team
INSERT INTO  dbo.Entity (Name, Description, TeamID, EntityTypeID, MaxSendingPause)
VALUES (@Name, @Description, @TeamID, 2, @MaxSendingPause)

SELECT @ID = @@IDENTITY

INSERT INTO dbo.EntityAttribute (EntityID, EntityAttributeTypeID, Value)
		  SELECT @ID, 'MODL', @Model
UNION ALL SELECT @ID, 'SRN', @RegistrationNumber
UNION ALL SELECT @ID, 'CLR', @Color
GO
